// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyConstructDataBinningAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyConstructDataBinningAttributes
//
// Purpose:
//   Attributes for constructing a data binning
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a ConstructDataBinningAttributes.
//
struct ConstructDataBinningAttributesObject
{
    PyObject_HEAD
    ConstructDataBinningAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewConstructDataBinningAttributes(int);
std::string
PyConstructDataBinningAttributes_ToString(const ConstructDataBinningAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    snprintf(tmpStr, 1000, "%sname = \"%s\"\n", prefix, atts->GetName().c_str());
    str += tmpStr;
    {   const stringVector &varnames = atts->GetVarnames();
        snprintf(tmpStr, 1000, "%svarnames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < varnames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", varnames[i].c_str());
            str += tmpStr;
            if(i < varnames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const unsignedCharVector &binType = atts->GetBinType();
        snprintf(tmpStr, 1000, "%sbinType = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < binType.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", int(binType[i]));
            str += tmpStr;
            if(i < binType.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &binBoundaries = atts->GetBinBoundaries();
        snprintf(tmpStr, 1000, "%sbinBoundaries = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < binBoundaries.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", binBoundaries[i]);
            str += tmpStr;
            if(i < binBoundaries.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    const char *reductionOperator_names = "Average, Minimum, Maximum, StandardDeviation, Variance, "
        "Sum, Count, RMS, PDF";
    switch (atts->GetReductionOperator())
    {
      case ConstructDataBinningAttributes::Average:
          snprintf(tmpStr, 1000, "%sreductionOperator = %sAverage  # %s\n", prefix, prefix, reductionOperator_names);
          str += tmpStr;
          break;
      case ConstructDataBinningAttributes::Minimum:
          snprintf(tmpStr, 1000, "%sreductionOperator = %sMinimum  # %s\n", prefix, prefix, reductionOperator_names);
          str += tmpStr;
          break;
      case ConstructDataBinningAttributes::Maximum:
          snprintf(tmpStr, 1000, "%sreductionOperator = %sMaximum  # %s\n", prefix, prefix, reductionOperator_names);
          str += tmpStr;
          break;
      case ConstructDataBinningAttributes::StandardDeviation:
          snprintf(tmpStr, 1000, "%sreductionOperator = %sStandardDeviation  # %s\n", prefix, prefix, reductionOperator_names);
          str += tmpStr;
          break;
      case ConstructDataBinningAttributes::Variance:
          snprintf(tmpStr, 1000, "%sreductionOperator = %sVariance  # %s\n", prefix, prefix, reductionOperator_names);
          str += tmpStr;
          break;
      case ConstructDataBinningAttributes::Sum:
          snprintf(tmpStr, 1000, "%sreductionOperator = %sSum  # %s\n", prefix, prefix, reductionOperator_names);
          str += tmpStr;
          break;
      case ConstructDataBinningAttributes::Count:
          snprintf(tmpStr, 1000, "%sreductionOperator = %sCount  # %s\n", prefix, prefix, reductionOperator_names);
          str += tmpStr;
          break;
      case ConstructDataBinningAttributes::RMS:
          snprintf(tmpStr, 1000, "%sreductionOperator = %sRMS  # %s\n", prefix, prefix, reductionOperator_names);
          str += tmpStr;
          break;
      case ConstructDataBinningAttributes::PDF:
          snprintf(tmpStr, 1000, "%sreductionOperator = %sPDF  # %s\n", prefix, prefix, reductionOperator_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%svarForReductionOperator = \"%s\"\n", prefix, atts->GetVarForReductionOperator().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sundefinedValue = %g\n", prefix, atts->GetUndefinedValue());
    str += tmpStr;
    const char *binningScheme_names = "Uniform, Unknown";
    switch (atts->GetBinningScheme())
    {
      case ConstructDataBinningAttributes::Uniform:
          snprintf(tmpStr, 1000, "%sbinningScheme = %sUniform  # %s\n", prefix, prefix, binningScheme_names);
          str += tmpStr;
          break;
      case ConstructDataBinningAttributes::Unknown:
          snprintf(tmpStr, 1000, "%sbinningScheme = %sUnknown  # %s\n", prefix, prefix, binningScheme_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    {   const intVector &numBins = atts->GetNumBins();
        snprintf(tmpStr, 1000, "%snumBins = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < numBins.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", numBins[i]);
            str += tmpStr;
            if(i < numBins.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    if(atts->GetOverTime())
        snprintf(tmpStr, 1000, "%soverTime = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%soverTime = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%stimeStart = %d\n", prefix, atts->GetTimeStart());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%stimeEnd = %d\n", prefix, atts->GetTimeEnd());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%stimeStride = %d\n", prefix, atts->GetTimeStride());
    str += tmpStr;
    const char *outOfBoundsBehavior_names = "Clamp, Discard";
    switch (atts->GetOutOfBoundsBehavior())
    {
      case ConstructDataBinningAttributes::Clamp:
          snprintf(tmpStr, 1000, "%soutOfBoundsBehavior = %sClamp  # %s\n", prefix, prefix, outOfBoundsBehavior_names);
          str += tmpStr;
          break;
      case ConstructDataBinningAttributes::Discard:
          snprintf(tmpStr, 1000, "%soutOfBoundsBehavior = %sDiscard  # %s\n", prefix, prefix, outOfBoundsBehavior_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    return str;
}

static PyObject *
ConstructDataBinningAttributes_Notify(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetName(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the name in the object.
    obj->data->SetName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetName(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetName().c_str());
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetVarnames(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetVarnames() = vec;
    // Mark the varnames in the object as modified.
    obj->data->SelectVarnames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetVarnames(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the varnames.
    const stringVector &varnames = obj->data->GetVarnames();
    PyObject *retval = PyTuple_New(varnames.size());
    for(size_t i = 0; i < varnames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(varnames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetBinType(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    typedef unsigned char uchar;
    ucharVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        uchar cval = uchar(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ uchar");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ uchar");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            uchar cval = uchar(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ uchar", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ uchar", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more uchars");

    obj->data->GetBinType() = vec;
    // Mark the binType in the object as modified.
    obj->data->SelectBinType();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetBinType(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the binType.
    const unsignedCharVector &binType = obj->data->GetBinType();
    PyObject *retval = PyTuple_New(binType.size());
    for(size_t i = 0; i < binType.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(binType[i])));
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetBinBoundaries(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetBinBoundaries() = vec;
    // Mark the binBoundaries in the object as modified.
    obj->data->SelectBinBoundaries();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetBinBoundaries(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the binBoundaries.
    const doubleVector &binBoundaries = obj->data->GetBinBoundaries();
    PyObject *retval = PyTuple_New(binBoundaries.size());
    for(size_t i = 0; i < binBoundaries.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(binBoundaries[i]));
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetReductionOperator(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 9)
    {
        std::stringstream ss;
        ss << "An invalid reductionOperator value was given." << std::endl;
        ss << "Valid values are in the range [0,8]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Average";
        ss << ", Minimum";
        ss << ", Maximum";
        ss << ", StandardDeviation";
        ss << ", Variance";
        ss << ", Sum";
        ss << ", Count";
        ss << ", RMS";
        ss << ", PDF";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the reductionOperator in the object.
    obj->data->SetReductionOperator(ConstructDataBinningAttributes::ReductionOperator(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetReductionOperator(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetReductionOperator()));
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetVarForReductionOperator(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the varForReductionOperator in the object.
    obj->data->SetVarForReductionOperator(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetVarForReductionOperator(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetVarForReductionOperator().c_str());
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetUndefinedValue(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the undefinedValue in the object.
    obj->data->SetUndefinedValue(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetUndefinedValue(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetUndefinedValue());
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetBinningScheme(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid binningScheme value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Uniform";
        ss << ", Unknown";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the binningScheme in the object.
    obj->data->SetBinningScheme(ConstructDataBinningAttributes::BinningScheme(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetBinningScheme(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetBinningScheme()));
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetNumBins(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetNumBins() = vec;
    // Mark the numBins in the object as modified.
    obj->data->SelectNumBins();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetNumBins(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the numBins.
    const intVector &numBins = obj->data->GetNumBins();
    PyObject *retval = PyTuple_New(numBins.size());
    for(size_t i = 0; i < numBins.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(numBins[i])));
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetOverTime(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the overTime in the object.
    obj->data->SetOverTime(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetOverTime(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetOverTime()?1L:0L);
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetTimeStart(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the timeStart in the object.
    obj->data->SetTimeStart(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetTimeStart(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetTimeStart()));
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetTimeEnd(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the timeEnd in the object.
    obj->data->SetTimeEnd(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetTimeEnd(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetTimeEnd()));
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetTimeStride(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the timeStride in the object.
    obj->data->SetTimeStride(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetTimeStride(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetTimeStride()));
    return retval;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_SetOutOfBoundsBehavior(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid outOfBoundsBehavior value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Clamp";
        ss << ", Discard";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the outOfBoundsBehavior in the object.
    obj->data->SetOutOfBoundsBehavior(ConstructDataBinningAttributes::OutOfBoundsBehavior(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ConstructDataBinningAttributes_GetOutOfBoundsBehavior(PyObject *self, PyObject *args)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetOutOfBoundsBehavior()));
    return retval;
}



PyMethodDef PyConstructDataBinningAttributes_methods[CONSTRUCTDATABINNINGATTRIBUTES_NMETH] = {
    {"Notify", ConstructDataBinningAttributes_Notify, METH_VARARGS},
    {"SetName", ConstructDataBinningAttributes_SetName, METH_VARARGS},
    {"GetName", ConstructDataBinningAttributes_GetName, METH_VARARGS},
    {"SetVarnames", ConstructDataBinningAttributes_SetVarnames, METH_VARARGS},
    {"GetVarnames", ConstructDataBinningAttributes_GetVarnames, METH_VARARGS},
    {"SetBinType", ConstructDataBinningAttributes_SetBinType, METH_VARARGS},
    {"GetBinType", ConstructDataBinningAttributes_GetBinType, METH_VARARGS},
    {"SetBinBoundaries", ConstructDataBinningAttributes_SetBinBoundaries, METH_VARARGS},
    {"GetBinBoundaries", ConstructDataBinningAttributes_GetBinBoundaries, METH_VARARGS},
    {"SetReductionOperator", ConstructDataBinningAttributes_SetReductionOperator, METH_VARARGS},
    {"GetReductionOperator", ConstructDataBinningAttributes_GetReductionOperator, METH_VARARGS},
    {"SetVarForReductionOperator", ConstructDataBinningAttributes_SetVarForReductionOperator, METH_VARARGS},
    {"GetVarForReductionOperator", ConstructDataBinningAttributes_GetVarForReductionOperator, METH_VARARGS},
    {"SetUndefinedValue", ConstructDataBinningAttributes_SetUndefinedValue, METH_VARARGS},
    {"GetUndefinedValue", ConstructDataBinningAttributes_GetUndefinedValue, METH_VARARGS},
    {"SetBinningScheme", ConstructDataBinningAttributes_SetBinningScheme, METH_VARARGS},
    {"GetBinningScheme", ConstructDataBinningAttributes_GetBinningScheme, METH_VARARGS},
    {"SetNumBins", ConstructDataBinningAttributes_SetNumBins, METH_VARARGS},
    {"GetNumBins", ConstructDataBinningAttributes_GetNumBins, METH_VARARGS},
    {"SetOverTime", ConstructDataBinningAttributes_SetOverTime, METH_VARARGS},
    {"GetOverTime", ConstructDataBinningAttributes_GetOverTime, METH_VARARGS},
    {"SetTimeStart", ConstructDataBinningAttributes_SetTimeStart, METH_VARARGS},
    {"GetTimeStart", ConstructDataBinningAttributes_GetTimeStart, METH_VARARGS},
    {"SetTimeEnd", ConstructDataBinningAttributes_SetTimeEnd, METH_VARARGS},
    {"GetTimeEnd", ConstructDataBinningAttributes_GetTimeEnd, METH_VARARGS},
    {"SetTimeStride", ConstructDataBinningAttributes_SetTimeStride, METH_VARARGS},
    {"GetTimeStride", ConstructDataBinningAttributes_GetTimeStride, METH_VARARGS},
    {"SetOutOfBoundsBehavior", ConstructDataBinningAttributes_SetOutOfBoundsBehavior, METH_VARARGS},
    {"GetOutOfBoundsBehavior", ConstructDataBinningAttributes_GetOutOfBoundsBehavior, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
ConstructDataBinningAttributes_dealloc(PyObject *v)
{
   ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *ConstructDataBinningAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyConstructDataBinningAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "name") == 0)
        return ConstructDataBinningAttributes_GetName(self, NULL);
    if(strcmp(name, "varnames") == 0)
        return ConstructDataBinningAttributes_GetVarnames(self, NULL);
    if(strcmp(name, "binType") == 0)
        return ConstructDataBinningAttributes_GetBinType(self, NULL);
    if(strcmp(name, "binBoundaries") == 0)
        return ConstructDataBinningAttributes_GetBinBoundaries(self, NULL);
    if(strcmp(name, "reductionOperator") == 0)
        return ConstructDataBinningAttributes_GetReductionOperator(self, NULL);
    if(strcmp(name, "Average") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::Average));
    if(strcmp(name, "Minimum") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::Minimum));
    if(strcmp(name, "Maximum") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::Maximum));
    if(strcmp(name, "StandardDeviation") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::StandardDeviation));
    if(strcmp(name, "Variance") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::Variance));
    if(strcmp(name, "Sum") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::Sum));
    if(strcmp(name, "Count") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::Count));
    if(strcmp(name, "RMS") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::RMS));
    if(strcmp(name, "PDF") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::PDF));

    if(strcmp(name, "varForReductionOperator") == 0)
        return ConstructDataBinningAttributes_GetVarForReductionOperator(self, NULL);
    if(strcmp(name, "undefinedValue") == 0)
        return ConstructDataBinningAttributes_GetUndefinedValue(self, NULL);
    if(strcmp(name, "binningScheme") == 0)
        return ConstructDataBinningAttributes_GetBinningScheme(self, NULL);
    if(strcmp(name, "Uniform") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::Uniform));
    if(strcmp(name, "Unknown") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::Unknown));

    if(strcmp(name, "numBins") == 0)
        return ConstructDataBinningAttributes_GetNumBins(self, NULL);
    if(strcmp(name, "overTime") == 0)
        return ConstructDataBinningAttributes_GetOverTime(self, NULL);
    if(strcmp(name, "timeStart") == 0)
        return ConstructDataBinningAttributes_GetTimeStart(self, NULL);
    if(strcmp(name, "timeEnd") == 0)
        return ConstructDataBinningAttributes_GetTimeEnd(self, NULL);
    if(strcmp(name, "timeStride") == 0)
        return ConstructDataBinningAttributes_GetTimeStride(self, NULL);
    if(strcmp(name, "outOfBoundsBehavior") == 0)
        return ConstructDataBinningAttributes_GetOutOfBoundsBehavior(self, NULL);
    if(strcmp(name, "Clamp") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::Clamp));
    if(strcmp(name, "Discard") == 0)
        return PyInt_FromLong(long(ConstructDataBinningAttributes::Discard));



    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyConstructDataBinningAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyConstructDataBinningAttributes_methods[i].ml_name),
                PyString_FromString(PyConstructDataBinningAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyConstructDataBinningAttributes_methods, self, name);
}

int
PyConstructDataBinningAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "name") == 0)
        obj = ConstructDataBinningAttributes_SetName(self, args);
    else if(strcmp(name, "varnames") == 0)
        obj = ConstructDataBinningAttributes_SetVarnames(self, args);
    else if(strcmp(name, "binType") == 0)
        obj = ConstructDataBinningAttributes_SetBinType(self, args);
    else if(strcmp(name, "binBoundaries") == 0)
        obj = ConstructDataBinningAttributes_SetBinBoundaries(self, args);
    else if(strcmp(name, "reductionOperator") == 0)
        obj = ConstructDataBinningAttributes_SetReductionOperator(self, args);
    else if(strcmp(name, "varForReductionOperator") == 0)
        obj = ConstructDataBinningAttributes_SetVarForReductionOperator(self, args);
    else if(strcmp(name, "undefinedValue") == 0)
        obj = ConstructDataBinningAttributes_SetUndefinedValue(self, args);
    else if(strcmp(name, "binningScheme") == 0)
        obj = ConstructDataBinningAttributes_SetBinningScheme(self, args);
    else if(strcmp(name, "numBins") == 0)
        obj = ConstructDataBinningAttributes_SetNumBins(self, args);
    else if(strcmp(name, "overTime") == 0)
        obj = ConstructDataBinningAttributes_SetOverTime(self, args);
    else if(strcmp(name, "timeStart") == 0)
        obj = ConstructDataBinningAttributes_SetTimeStart(self, args);
    else if(strcmp(name, "timeEnd") == 0)
        obj = ConstructDataBinningAttributes_SetTimeEnd(self, args);
    else if(strcmp(name, "timeStride") == 0)
        obj = ConstructDataBinningAttributes_SetTimeStride(self, args);
    else if(strcmp(name, "outOfBoundsBehavior") == 0)
        obj = ConstructDataBinningAttributes_SetOutOfBoundsBehavior(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
ConstructDataBinningAttributes_print(PyObject *v, FILE *fp, int flags)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)v;
    fprintf(fp, "%s", PyConstructDataBinningAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
ConstructDataBinningAttributes_str(PyObject *v)
{
    ConstructDataBinningAttributesObject *obj = (ConstructDataBinningAttributesObject *)v;
    return PyString_FromString(PyConstructDataBinningAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *ConstructDataBinningAttributes_Purpose = "Attributes for constructing a data binning";
#else
static char *ConstructDataBinningAttributes_Purpose = "Attributes for constructing a data binning";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(ConstructDataBinningAttributesType,         \
                  "ConstructDataBinningAttributes",           \
                  ConstructDataBinningAttributesObject,       \
                  ConstructDataBinningAttributes_dealloc,     \
                  ConstructDataBinningAttributes_print,       \
                  PyConstructDataBinningAttributes_getattr,   \
                  PyConstructDataBinningAttributes_setattr,   \
                  ConstructDataBinningAttributes_str,         \
                  ConstructDataBinningAttributes_Purpose,     \
                  ConstructDataBinningAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
ConstructDataBinningAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &ConstructDataBinningAttributesType
         || Py_TYPE(other) != &ConstructDataBinningAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    ConstructDataBinningAttributes *a = ((ConstructDataBinningAttributesObject *)self)->data;
    ConstructDataBinningAttributes *b = ((ConstructDataBinningAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static ConstructDataBinningAttributes *defaultAtts = 0;
static ConstructDataBinningAttributes *currentAtts = 0;

static PyObject *
NewConstructDataBinningAttributes(int useCurrent)
{
    ConstructDataBinningAttributesObject *newObject;
    newObject = PyObject_NEW(ConstructDataBinningAttributesObject, &ConstructDataBinningAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new ConstructDataBinningAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new ConstructDataBinningAttributes(*defaultAtts);
    else
        newObject->data = new ConstructDataBinningAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapConstructDataBinningAttributes(const ConstructDataBinningAttributes *attr)
{
    ConstructDataBinningAttributesObject *newObject;
    newObject = PyObject_NEW(ConstructDataBinningAttributesObject, &ConstructDataBinningAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (ConstructDataBinningAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
ConstructDataBinningAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewConstructDataBinningAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef ConstructDataBinningAttributesMethods[] = {
    {"ConstructDataBinningAttributes", ConstructDataBinningAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *ConstructDataBinningAttributesObserver = 0;

std::string
PyConstructDataBinningAttributes_GetLogString()
{
    std::string s("ConstructDataBinningAtts = ConstructDataBinningAttributes()\n");
    if(currentAtts != 0)
        s += PyConstructDataBinningAttributes_ToString(currentAtts, "ConstructDataBinningAtts.", true);
    return s;
}

static void
PyConstructDataBinningAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("ConstructDataBinningAtts = ConstructDataBinningAttributes()\n");
        s += PyConstructDataBinningAttributes_ToString(currentAtts, "ConstructDataBinningAtts.", true);
        cb(s);
    }
}

void
PyConstructDataBinningAttributes_StartUp(ConstructDataBinningAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyConstructDataBinningAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(ConstructDataBinningAttributesObserver == 0)
    {
        ConstructDataBinningAttributesObserver = new ObserverToCallback(subj,
            PyConstructDataBinningAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyConstructDataBinningAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete ConstructDataBinningAttributesObserver;
    ConstructDataBinningAttributesObserver = 0;
}

PyMethodDef *
PyConstructDataBinningAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return ConstructDataBinningAttributesMethods;
}

bool
PyConstructDataBinningAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &ConstructDataBinningAttributesType);
}

ConstructDataBinningAttributes *
PyConstructDataBinningAttributes_FromPyObject(PyObject *obj)
{
    ConstructDataBinningAttributesObject *obj2 = (ConstructDataBinningAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyConstructDataBinningAttributes_New()
{
    return NewConstructDataBinningAttributes(0);
}

PyObject *
PyConstructDataBinningAttributes_Wrap(const ConstructDataBinningAttributes *attr)
{
    return WrapConstructDataBinningAttributes(attr);
}

void
PyConstructDataBinningAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    ConstructDataBinningAttributesObject *obj2 = (ConstructDataBinningAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyConstructDataBinningAttributes_SetDefaults(const ConstructDataBinningAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new ConstructDataBinningAttributes(*atts);
}

